<?php
session_start();
    
    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // December 5, 2011
    // IN PARAMETERS : stepId
    // 
    // This AJAX Request gets all stepId information.

    include('../includes/siteConfig.php');
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // PASSED VARIABLES VIA POST
    $stepId = $_POST['stepId'];
    
    // GET STEP ID INFORMATION
    $query = 
        "
            SELECT *
            FROM RouteStep_Req_Attachment, DocumentSetup
            WHERE RouteStep_Req_Attachment.stepId = '$stepId' AND
                  RouteStep_Req_Attachment.documentSetupId = DocumentSetup.documentSetupId
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
     
    // SAVE QUERY RESULTS TO AN ARRAY > $row. Each row will be placed to a list ($attachmentList).  
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_array($result)) {
        $attachmentData = array();
        $attachmentData['documentName'] = $row['documentName'];

        $attachmentList[] = $attachmentData;
        }
        
        echo json_encode($attachmentList);
    }
    
    else {
        echo json_encode(0);
    }
    

    mysql_free_result($result);
    mysql_close($connect);
    
   
?>
